/*
 * @description: 
 * @Author: Islands
 * @Date: 2024-06-17 21:26:27
 * @LastEditTime: 2024-08-11 22:54:40
 */

import { ElLoading } from 'element-plus';
import { ElMessage, ElMessageBox } from 'element-plus'

/**
*  倒计时
*  @param {Number} second 倒计时秒数
*  @return {Number} count 倒计时秒数
*  @return {Function} countDown 倒计时函数
*  @example
*/
export function useCountDown() {
    const countdown = ref(0);
    const countDown = (second: any) => {
        if (countdown.value === 0) {
            countdown.value = second; // 设置倒计时时间，如60秒
            const intervalId = setInterval(() => {
                if (countdown.value > 0) {
                    countdown.value--;
                } else {
                    clearInterval(intervalId);
                }
            }, 1000);
        }
    };
    return {
        countdown,
        countDown,
    };
}


/**
*  开关
*  @param {Boolean} flag 开关标记
*  @return {Function} open 开
* @return {Function} close 关
*  @example
*/
export function useSwitch() {
    const flag = ref(false);
    const open = () => {
        flag.value = true;
    };
    const close = () => {
        flag.value = false;
    }
    return {
        flag,
        open,
        close
    };
}

/** 加载动画 */
export function useLoading() {
    let loading: any;
    //只需要续不加载 ，设置 id=special-node   使用 指令 v-loading
    // const specialNode:any = document.getElementById('special-node');
    const startLoading = () => {
        loading = ElLoading.service({
            fullscreen: true,
            lock: true,
            spinner: '',
            text: 'Loading...',
            background: 'rgba(0, 0, 0, 0.7)',
            // target: specialNode
        });
    };
    const endLoading = () => {
        loading.close();
    }
    return {
        startLoading, endLoading
    };
}

